package com.david.mydemo.ctl_redis.message.listen;

import com.alibaba.fastjson.JSON;
import com.david.mydemo.ctl_redis.dto.UserDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RedisUserMsgV2t2Handler extends RedisBaseListener {

    @Override
    public void onMessage(Message message, byte[] pattern) {
        byte[] body = message.getBody();
        String json = RedisSerializer.string().deserialize(body);
        UserDto userDto = JSON.parseObject(json, UserDto.class);
        log.info("handle2接收到：{}", userDto);
    }

    @Override
    public String getTopic() {
        return "user-topic2";
    }
}
